{extend name="public:base" title="$list_base.title" /}
{block name="cont"}
<form class="layout layui-form" action="{:url('articlelist',['id' => $postdb.id])}" lay-filter="articlelist" method="post">
    <div class="cx-xs16">
        <div class="layui-tab layui-tab-brief" lay-filter="code">
            <ul class="layui-tab-title">
                <li class="layui-this">系统模板</li>
                <li>自订义模板</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="cx-form-group cx-mag-b10">
                        <label class="cx-label">模板类型</label>
                        <div class="cx-form-item">
                            <input type="radio" name="temptype" value="1" title="单条循环" {eq name="postdb.temptype|default='0'" value="1"}checked{/eq} lay-filter="temptype">
                            <input type="radio" name="temptype" value="0" title="模块引用" {eq name="postdb.temptype|default='0'" value="0"}checked{/eq} lay-filter="temptype">
                        </div>
                    </div>
                    <div class="cx-form-group cx-mag-b10 ">
                        <label class="cx-label">展示模板</label>
                        <div class="cx-form-item cx-fex-column">
                            <select class="latename" name="latename" lay-filter="onetemplate">
                                <option value="0">默认模板</option>
                                {volist name="filelist" id="cx" empty=""}
                                <option value="{$cx}" {eq name="postdb.latename|default=''" value="$cx"}selected{/eq}>{$cx}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="cx-form-group cx-mag-b10 ">
                        <label class="cx-label">模板预览</label>
                        <div class="cx-form-item cx-fex-column">
                            <div class="cx-fex-c cx-fex-itemsc cx-bor cx-mag-t10" style="width: 30%;">
                                <img class="onetemplateimg cx-img-responsive" {eq name="postdb.temptype|default='0'" value="1"}src="/public/label/articlelist/one/{$postdb.latename|default=''}.jpg"{else /}src="/public/label/articlelist/list/{$postdb.latename|default=''}.jpg"{/eq} onerror="this.src='__PUBLIC__/img/imgnone.jpg'">
                            </div>
                        </div>
                    </div>
                    <div class="cx-form-group cx-mag-b10 ">
                        <label class="cx-label">标题字数</label>
                        <div class="cx-form-item">
                            <div class="layout cx-form-itemnowarp">
                                <input class="cx-ipt " type="number" placeholder="请输入标题显示字数" name="conf[title_num]" value="{$postdb.conf.title_num|default='0'}">
                                <div class="cx-ipt-icon cx-bg-white-4"> / 字</div>
                            </div>
                            <div class="layout cx-text-black-3">0为全部显示</div>
                        </div>
                    </div>
                    <div class="cx-form-group cx-mag-b10 ">
                        <label class="cx-label">简介字数</label>
                        <div class="cx-form-item">
                            <div class="layout cx-form-itemnowarp">
                                <input class="cx-ipt " type="number" placeholder="请输入简介显示字数" name="conf[description_num]" value="{$postdb.conf.description_num|default='0'}">
                                <div class="cx-ipt-icon cx-bg-white-4"> / 字</div>
                            </div>
                            <div class="layout cx-text-black-3">0为全部显示</div>
                        </div>
                    </div>
                    <div class="cx-form-group cx-mag-b10 ">
                        <label class="cx-label">显示类型</label>
                        <div class="cx-form-item">
                            <select name="conf[jian]">
                                <option {eq name="postdb.conf.jian|default='0'" value="0"} selected{/eq} value="0">全部(包含推荐和未推荐)</option>
                                <option {eq name="postdb.conf.jian|default='0'" value="10"} selected{/eq} value="10">全部推荐内容</option>
                                <option {eq name="postdb.conf.jian|default='0'" value="9"} selected{/eq} value="9">固定置顶</option>
                                <option {eq name="postdb.conf.jian|default='0'" value="6"} selected{/eq} value="6">6级推荐</option>
                                <option {eq name="postdb.conf.jian|default='0'" value="5"} selected{/eq} value="5">5级推荐</option>
                                <option {eq name="postdb.conf.jian|default='0'" value="4"} selected{/eq} value="4">4级推荐</option>
                                <option {eq name="postdb.conf.jian|default='0'" value="3"} selected{/eq} value="3">3级推荐</option>
                                <option {eq name="postdb.conf.jian|default='0'" value="2"} selected{/eq} value="2">2级推荐</option>
                                <option {eq name="postdb.conf.jian|default='0'" value="1"} selected{/eq} value="1">1级推荐</option>
                            </select>
                        </div>
                    </div>
                    <div class="cx-form-group cx-mag-b10 ">
                        <label class="cx-label">封面图</label>
                        <div class="cx-form-item">
                            <input type="radio" name="conf[picurl]" value="0" title="全部 " {eq name="postdb.conf.picurl|default='0'" value="0"}checked{/eq} lay-filter="picurl">
                            <input type="radio" name="conf[picurl]" value="1" title="仅显示有封面图 " {eq name="postdb.conf.picurl|default='0'" value="1"}checked{/eq} lay-filter="picurl">
                        </div>
                    </div>
                </div>
                <div class="layui-tab-item">
                    <div class="cx-form-group cx-mag-b10 ">
                        <label class="cx-label">模板代码</label>
                        <div class="cx-form-item cx-fex-column">
                            <textarea class="cx-ipt cx-text-f16 cx-mag-t10 onetemplateval" rows="10" name="template" style="line-height: 2;">{$postdb.template|default=''|raw}</textarea>
                            <div class="layout cx-text-black-3">不懂代码请勿修改，代码说明：<a href="//www.wormcms.com" target="_blank">说明文档</a></div>
                        </div>
                    </div>
                    <div class="cx-form-group cx-mag-b10 ">
                        <label class="cx-label">可用参数</label>
                        <div class="cx-form-item cx-fex-column">
                            <div class="layout cx-text-black-6 cx-text-lh">模块引用循环变量名为: _LIST_。单条循环变量名为 $res，如调用栏目名称：{literal} {$res.title|default=''} {/literal}</div>
                            <table class="layui-table">
                                <thead>
                                <tr>
                                    <th>字段名</th>
                                    <th>说明</th>
                                </tr>
                                </thead>
                                <tbody class="_fileview"></tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="cx-xs8">
        <div class="cx-form-group _listlate cx-mag-b10 ">
            <label class="cx-label" for="title">标签名称</label>
            <div class="cx-form-item">
                <input id="title" class="cx-ipt " type="text" placeholder="请输入标签名称" name="title" value="{$postdb.title|default=$postdb.TagName}">
            </div>
        </div>
        <div class="cx-form-group _listlate cx-mag-b10 ">
            <label class="cx-label">选择模型</label>
            <div class="cx-form-item cx-pad-t5">
                {volist name="modellist" id="cx" empty=""}
                <input class="onemodel" type="checkbox" name="TagMid[]" value="{$cx.id}" title="{$cx.title}" lay-skin="primary" lay-filter="onemodel" {in name="cx.id" value="$postdb.TagMid|default='0'"}checked{/in}>
                {/volist}
                <div class="layout cx-text-black-3">如不选择则按默认显示</div>
            </div>
        </div>
        <div class="cx-form-group cx-mag-b10 ">
            <label class="cx-label">选择栏目</label>
            <div class="cx-form-item cx-fex-column cx-pad-t5">
                <div class="layout cx-bor cx-bor-black-1 _partlist" style="overflow-y: auto;">
                    <ul class="layout cx-fex-l cx-fex-column cx-pad-lr15 _fidlist">
                        {volist name="partlist" id="cx" empty=""}
                        <li class="cx-pad-tb5">
                            <input type="checkbox" name="TagFid[]" value="{$cx.id}" title="{$cx.title}" lay-skin="primary" {in name="cx.id" value="$postdb.TagFid|default='0'"}checked{/in}>
                        </li>
                        {/volist}
                    </ul>
                </div>
                <div class="layout cx-text-black-3">如不选择则显示全部</div>
            </div>
        </div>
        <div class="cx-form-group _listlate cx-mag-b10 ">
            <label class="cx-label">显示条数</label>
            <div class="cx-form-item">
                <div class="layout cx-form-itemnowarp">
                    <input id="price" class="cx-ipt " type="number" placeholder="请输入显示条数" name="TagLimit" value="{$postdb.TagLimit|default='0'}">
                    <div class="cx-ipt-icon cx-bg-white-4"> / 条</div>
                </div>
                <div class="layout cx-text-black-3">0为默认显示</div>
            </div>
        </div>
        <div class="cx-form-group _listlate cx-mag-b10 ">
            <label class="cx-label">排序规则</label>
            <div class="cx-form-item">
                <select name="TagOrder">
                    <option value="0" {eq name="postdb.TagOrder" value="0"}selected{/eq}>模板默认排序</option>
                    <option value="jian desc,addtime desc,id desc" {eq name="postdb.TagOrder" value="jian desc,addtime desc,id desc"}selected{/eq}>默认排序</option>
                    <option value="sort desc" {eq name="postdb.TagOrder" value="sort desc"}selected{/eq}>排序值降序</option>
                    <option value="sort asc" {eq name="postdb.TagOrder" value="sort asc"}selected{/eq}>排序值升序</option>
                    <option value="id desc" {eq name="postdb.TagOrder" value="id desc"}selected{/eq}>发表时间降序</option>
                    <option value="id asc" {eq name="postdb.TagOrder" value="id asc"}selected{/eq}>发表时间升序</option>
                    <option value="hist desc" {eq name="postdb.TagOrder" value="hist desc"}selected{/eq}>点击量降序</option>
                    <option value="hist asc" {eq name="postdb.TagOrder" value="hist asc"}selected{/eq}>点击量升序</option>
                </select>
            </div>
        </div>
        <div class="cx-form-group _listlate cx-mag-b10 ">
            <label class="cx-label">启用</label>
            <div class="cx-form-item">
                <input type="radio" name="status" value="1" title="启用 " {eq name="postdb.status|default='1'" value="1"}checked{/eq} lay-filter="status">
                <input type="radio" name="status" value="0" title="禁用 " {eq name="postdb.status|default='1'" value="0"}checked{/eq} lay-filter="status">
            </div>
        </div>
    </div>
    <div class="layout cx-pos-f _listlate cx-bg-white cx-fex-r" style="bottom: 0;left: 0;right: 0;box-shadow: 0 0 5px 0 rgba(0,0,0,0.3);">
        <input type="hidden" name="id" value="{$postdb.id}" required>
        <button class="cx-xs3 cx-button cx-bg-yellow" lay-submit lay-filter="upbutton">保 存</button>
    </div>
</form>
{/block}
{block name="foot_js"}
<script>
    window.onload = function(){
        let h = $(window).height(),
            dv = 60;
        $.each($(`._listlate`),function (index,item) {
            dv = dv + $(item).height() + 10;
        });
        $(`._partlist`).height(h - dv);
    }
    layui.use('form', function(){
        let layform = layui.form,
            getfile = function (ids = ''){
                $.post("{:url('getfile')}",{n:ids,m:"{$postdb.TagModel}"},function (res){
                    if(res.code == '1'){
                        $(`._fileview`).html('');
                        $.each(res.data,function (index,item){
                            $(`._fileview`).append(`<tr><td>${item.filed}</td><td>${item.title}</td></tr>`);
                        });
                    }
                });
            };
        layform.on('select(onetemplate)', function(data){
            if(data.value == '0'){
                $(`.onetemplateimg`).attr('src','__PUBLIC__/img/imgnone.jpg');
                $(`.onetemplateval`).val('');
                return false;
            }
            let d = layform.val("articlelist"),
                n = d.temptype == '1' ? 'articlelist/one' : 'articlelist/list';
            wormui.postUrl("{:url('getcode')}",{n:n,f:data.value},function (res){
                if(res.code == '1'){
                    $(`.onetemplateimg`).attr('src',res.data.img);
                    $(`.onetemplateval`).val(res.data.code);
                }
            });
        });
        layform.on('checkbox(onemodel)', function(data){
            let ids = [];
            $(`.onemodel`).each(function(index,item) {
                $(item).is(':checked') ? ids.push($(item).val()) : ids;
            });
            wormui.postUrl("{:url('getpart')}",{n:ids,m:"{$postdb.TagModel}",c:'0'},function (res){
                if(res.code == '1'){
                    $(`._fidlist`).html('');
                    $.each(res.data,function (index,item){
                        $(`._fidlist`).append(` <li class="cx-pad-tb5"><input type="checkbox" name="TagFid[]" value="${item.id}" title="${item.title}" lay-skin="primary"></li>`);
                    });
                    layform.render('checkbox');
                }
            });
            getfile(ids);
        });
        getfile("{$postdb.TagMid|default=''}");
        //  模板类型选择
        layform.on('radio(temptype)',function (data){
            let d = data.value == '1' ? 'label/articlelist/one' : 'label/articlelist/list';
            wormui.postUrl("{:url('gettemplist')}",{d:d},function (res){
                if(res.code == '1'){
                    $(`.latename`).html(`<option value="0">默认模板</option>`);
                    $.each(res.data,function (index,item){
                        $(`.latename`).append(`<option value="${item}">${item}</option>`);
                    });
                    layform.render('select');
                }
            });
        });
    });
</script>
{/block}